package com.hong.taotaomall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hong.taotaomall.entity.ShoppingCart;
import com.hong.taotaomall.mapper.ShoppingCartMapper;
import com.hong.taotaomall.service.IShoppingCartService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 购物车 服务实现类
 * </p>
 *
 * @author hong
 * @since 2023-03-25
 */
@Service
public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, ShoppingCart> implements IShoppingCartService {

    @Autowired
    private IShoppingCartService shoppingCartService;

    @Transactional
    @Override
    public void deleteByIds(List<Long> ids) {
        LambdaQueryWrapper<ShoppingCart> lqw = new LambdaQueryWrapper<>();
        lqw.in(ids != null, ShoppingCart::getId, ids);
        List<ShoppingCart> list = shoppingCartService.list(lqw);
        for (ShoppingCart shoppingCart : list) {
            shoppingCartService.removeById(shoppingCart.getId());
        }
    }
}
